<template>
  <el-container>
    <el-header style="height: 47px;">
      <p>维修信息列表</p>
    </el-header>
    <el-main>
      <el-row class="btnGroup">
        <el-button class="twoBtn" @click="addBerth"><span>添加</span><i class="el-icon-plus"></i></el-button>
        <!--<el-button icon="el-icon-edit" @click="editBerth">编辑</el-button>-->
        <el-button class="twoBtn" @click="delBerth"><span>删除</span><i class="el-icon-delete"></i></el-button>
        <!--<el-button icon="el-icon-download">导出EXCEL</el-button>-->
      </el-row>
      <el-table
        :data="tableData.list"
        style="width:100%"
        height="600"
        ref="multipleTable"
        tooltip-effect="dark"
        stripe
        @selection-change="handleSelectionChange"
        v-loading="loading"
      >
        <el-table-column fixed align="center" type="selection" width="55"></el-table-column>
        <el-table-column fixed sortable align="center" prop="equipment_no" label="设备ID" width="180"></el-table-column>
        <el-table-column sortable align="center" prop="equipment_site" label="设备位置" width="150"></el-table-column>
        <el-table-column sortable align="center" prop="equipment_type" label="设备类型" width="150"></el-table-column>
        <el-table-column sortable align="center" prop="equipment_model" label="设备型号" width="150"></el-table-column>
        <el-table-column sortable align="center" prop="repair_problem_desc" label="问题描述" width="150"></el-table-column>
        <el-table-column sortable align="center" prop="equipment_operator" label="维修单位" width="170"></el-table-column>
        <el-table-column sortable align="center" prop="equipment_person" label="联系人" width="150"></el-table-column>
        <el-table-column sortable align="center" prop="equipment_phoneno" label="联系方式" width="150"></el-table-column>
        <el-table-column sortable align="center" prop="repair_time" label="维修时间" width="150"></el-table-column>
        <el-table-column fixed="right" align="center" width="100" label="操作">
          <template slot-scope="scope">
            <el-dropdown trigger="click" @command="handleCommand">
              <el-button class="downBtn" @click="changeRow(scope.row)">
                <i class="el-icon-arrow-down"></i>
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="edit">编辑</el-dropdown-item>
                <el-dropdown-item command="del">删除</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
    </el-main>
    <el-footer>
      <el-pagination
        background
        layout="total,sizes,prev,pager,next,jumper"
        :total="dataCount"
        :page-sizes="[10,20,30,50]"
        :page-size="dataPageSize"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
        style="margin-top: 16px;"
      ></el-pagination>
    </el-footer>
  </el-container>
</template>

<script>
  import {delBerth} from '../../../api/parkingResource/parkingSpace'
  import {getNum} from '../../../api/public/searchUnit'

  export default {
    name: 'repairMagTable',
    props: ['tableLoad', 'tableData'],
    data() {
      return {
        changeVal: '',
        dataCount: 0,
        dataPageSize: 10,
        multipleTable: [],
        loading: false,
        pageNum: 0,
        tempParkMag: {
          park_no: '',
          park_name: '',
          park_placeno: '',
          park_placeStart: '001',
          park_ssdw: '',
          park_ssdwname: '', park_sfbzname: '',
          park_sfbz: '', park_roadno: '', park_road: '', park_dllx: '',
          park_jdbsc: '', park_sroad: '', park_eroad: '', park_dlnc: '',
          park_sffs: '', park_jcfs: '', park_long: '', park_lati: '',
          park_sdate: '', park_edate: '', park_status: '1', park_remark: '',

          equipment_site: '',
          equipment_desc: '',
          equipment_status: '',
          equipment_type: '',
          equipment_person: '',
          equipment_phoneno: '',
          equipment_model: '',
          equipment_manager: '',
          equipment_operator: '',
          equipment_buy_time: '',
          equipment_long: '',
          equipment_lati: '',
          repair_time:'',
          repair_problem_desc: ''
        }
      }
    },
    watch: {
      tableLoad: function (val) {
        this.loading = val
      },
      tableData: function (val) {
        this.dataCount = val.count
        this.dataPageSize = val.pageSize
      }
    },
    methods: {
      addBerth: function () {
        this.$emit('addBerth', true)
      },
      editBerth: function () {
        if (this.multipleTable.length !== 1) {
          this.$message({
            message: '请选择一条记录',
            type: 'warning'
          })
          return
        }
        this.$emit('editBerth', [this.multipleTable[0], true])
      },
      delBerth: function () {
        if (this.multipleTable.length < 1) {
          this.$message({
            message: '请选择至少一条记录',
            type: 'warning'
          })
          return
        }
        this.$confirm('此操作将永久删除选中的记录,是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          let delData = []
          for (var i = 0; i < this.multipleTable.length; i++) {
            delData.push(this.multipleTable[i].place_id)
          }
          delBerth(delData).then(res => {
            this.$emit('delSearch', getNum())
            this.$message({
              message: '删除成功',
              type: 'success'
            })
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
      handleSelectionChange: function (val) {
        this.multipleTable = val
      },
      handleCurrentChange: function (val) {
        this.$emit('pageNum', val)
      },
      handleSizeChange: function (val) {
        this.$emit('pageSize', val)
      },
      handleCommand(val) {
        if (val === 'edit') {
          this.$emit('editBerth', [this.changeVal, true])
        } else {
          this.$confirm('此操作将永久删除选中的记录,是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            let delData = []
            delData.push(this.changeVal.place_id)
            delBerth(delData).then(res => {
              this.$emit('delSearch', getNum())
              this.$message({
                type: 'success',
                message: '删除成功'
              })
            })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            })
          })
        }
      },
      changeRow(val) {
        this.changeVal = Object.assign({}, val) // copy obj
      }
    }
  }
</script>

<style scoped>
  .el-dropdown {
    width: 33px;
    height: 19px;
  }

  .el-dropdown > .el-button {
    width: 33px;
    height: 19px;
    padding: 3px 9px;
  }

  .el-main {
    padding: 0;
    margin-top: 24px;
    margin-left: 24px;
  }

  .el-header p {
    font-family: MicrosoftYaHei;
    font-size: 13px;
    margin-top: 22px;
    color: #7F8CA6;
  }

  .el-header {
    padding: 0;
    margin-left: 24px;
    margin-right: 24px;
    border-bottom: 1px solid #E1E1E1;
  }

  .btnGroup {
  }

  .btnGroup > .twoBtn {
    width: 64px;
    height: 24px;
    padding: 4px 20px;
    border: 1px solid #409eff;
    font-family: MicrosoftYaHei;
    color: #fff;
    font-size: 12px;
  }

  .btnGroup > .fourBtn {
    width: 64px;
    height: 24px;
    padding: 4px 8px;
    border: 1px solid #409eff;
    font-family: MicrosoftYaHei;
    color: #fff;
    font-size: 12px;
  }

  .btnGroup > .el-button span {
    display: none;
  }

  .btnGroup > .el-button:hover {
    background-color: #409EFF;
  }

  .btnGroup > .el-button:hover span {
    display: block;
  }

  .btnGroup > .el-button:hover i {
    display: none;
  }

  .el-button i {
    color: #409eff;
  }

  .el-footer {
    text-align: right;
  }
</style>
